package cn.easybuy.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * 登录的servlet
 * 
 * 
		密码加密的思路
		  用户会从页面输入一个值   这个值借助 md5工具类, 可以进行加密(不可逆的算法,很安全)
		  加密后的字符串再去和数据匹配, 如果能匹配上,那就是密码正确
		 匹配补上,就是密码错误
		 
		 注册同理(略)
		 
		 加密的工具类详见 util.SecurityUtils
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		//避免前端请求 servlet 进不来
		System.out.println("-------------进入了登录的Servlet  LoginServlet----------- ");
		
		//接收用户名 & 密码
		String username = request.getParameter("username");
		String password = request.getParameter("password");//jljjlj
		
		System.out.println("用户名: "+ username);
		System.out.println("密码: "+ password);
		
		//调用Service方法 验证 账密是否正确
		String sec_pwd = DigestUtils.md5Hex(password); //加密后的密码
		//密码能不能再次加密??
		sec_pwd = DigestUtils.md5Hex(sec_pwd); //二次加密
		System.out.println("加密后的密码:" + sec_pwd);
		
		//页面跳转 ,跳到首页
		
		//response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
